<template>
  <div class="allbox">
    <div class="words1">请选择使用需求，方便我们更好地为您服务</div>
    <div class="words2">
      请选择角色
      <span>（跳过后可在个人中心再次重新选择）</span>
    </div>
    <div class="choose">
      <div @click="renter">租客<img src="../assets/role01.png" alt="" /></div>
      <div @click="rentowner">
        房东<img src="../assets/role02.png" alt="" />
      </div>
      <div @click="buy">买家<img src="../assets/role03.png" alt="" /></div>
      <div @click="owner">业主<img src="../assets/role04.png" alt="" /></div>
      <div @click="agent">经纪人<img src="../assets/role05.png" alt="" /></div>
    </div>
    <div class="pass"><span @click="pass">跳过</span></div>
  </div>
</template>

<script>
import { changerole } from "../apis/user";
import { _local } from "@/utils/storage";
import { setToken, setUserId, setRyToken } from "@/utils/auth";
export default {
  methods: {
    renter() {
      changerole({ role: "1" }).then((res) => {
        console.log("切换租客身份", res);
        if (res.code == 200 || res.code == 201) {
          setUserId(res.result.userId);
          setToken(res.result.token);
          setRyToken(res.result.ryToken);
          this.$router.push({ path: "/home/me" });
        } else if (res.code == 3024) {
          this.$router.push({ path: "/home/me" });
        }
      });
    },
    rentowner() {
      if (_local.get("user").result.is_rent_house == 1) {
        changerole({ role: "2" }).then((res) => {
          console.log("切换房东身份", res);
          if (res.code == 200 || res.code == 201) {
            setUserId(res.result.userId);
            setToken(res.result.token);
            setRyToken(res.result.ryToken);
            this.$router.push({ path: "/home/me" });
          } else if (res.code == 3024) {
            this.$router.push({ path: "/home/me" });
          }
        });
      } else {
        this.$router.push({ path: "/releasehouse" });
      }
    },
    buy() {
      changerole({ role: "5" }).then((res) => {
        console.log("切换买家身份", res);
        if (res.code == 200 || res.code == 201) {
          setUserId(res.result.userId);
          setToken(res.result.token);
          setRyToken(res.result.ryToken);
          this.$router.push({ path: "/home/me" });
        } else if (res.code == 3024) {
          this.$router.push({ path: "/home/me" });
        }
      });
    },
    owner() {
      if (_local.get("user").result.is_second_house == 1) {
        changerole({ role: "3" }).then((res) => {
          console.log("切换业主身份", res);
          if (res.code == 200 || res.code == 201) {
            setUserId(res.result.userId);
            setToken(res.result.token);
            setRyToken(res.result.ryToken);
            this.$router.push({ path: "/home/me" });
          } else if (res.code == 3024) {
            this.$router.push({ path: "/home/me" });
          }
        });
      } else {
        this.$router.push({ path: "/buysell" });
      }
    },
    agent() {
      if (_local.get("user").result.is_agent == 1) {
        changerole({ role: "4" }).then((res) => {
          console.log("切换经纪人身份", res);
          if (res.code == 200 || res.code == 201) {
            setUserId(res.result.userId);
            setToken(res.result.token);
            setRyToken(res.result.ryToken);
            this.$router.push({ path: "/home/me" });
          } else if (res.code == 3024) {
            this.$router.push({ path: "/home/me" });
          }
        });
      } else {
        this.$router.push({ path: "/graborder" });
      }
    },
    pass() {
      this.$router.push({ path: "/home/me" });
    },
  },
};
</script>

<style lang="less" scoped>
.allbox {
  margin: 0 9.3vw;
  padding-top: 5px;
  .words1 {
    margin-top: 8px;
    margin-left: 5px;
    font-size: 14px;
    color: rgba(51, 51, 51, 0.781);
  }
  .words2 {
    margin-left: 5px;
    font-size: 18px;
    font-weight: 550;
    color: #333;
    margin-top: 20px;
    span {
      font-size: 12px;
      color: gray;
    }
  }
  .choose {
    margin-top: 15px;
    text-align: center;
    > div {
      width: 81.3vw;
      height: 24vw;
      margin-bottom: 15px;
      font-size: 18px;
      color: #fff;
      display: flex;
      padding: 0 8vw;
      box-sizing: border-box;
      justify-content: space-between;
      align-items: center;
      img {
        width: 55px;
        height: 55px;
      }
      &:first-child {
        background: url("../assets/rolebg01.png") no-repeat 0px 0px;
        background-size: 100% 100%;
        box-shadow: 3px 3px 3px#EEBB53;
      }
      &:nth-child(2) {
        background: url("../assets/rolebg02.png") no-repeat 0px 0px;
        background-size: 100% 100%;
        box-shadow: 3px 3px 3px#FF8224;
      }
      &:nth-child(3) {
        background: url("../assets/rolebg03.png") no-repeat 0px 0px;
        background-size: 100% 100%;
        box-shadow: 3px 3px 3px#33D1C7;
      }
      &:nth-child(4) {
        background: url("../assets/rolebg04.png") no-repeat 0px 0px;
        background-size: 100% 100%;
        box-shadow: 3px 3px 3px#3CA0FE;
      }
      &:last-child {
        background: url("../assets/rolebg05.png") no-repeat 0px 0px;
        background-size: 100% 100%;
        box-shadow: 3px 3px 3px#45B7CB;
      }
    }
  }
  .pass {
    padding-top: 10px;
    text-align: center;
    span {
      color: #45b7cb;
      border: 1px solid #45b7cb;
      padding: 7px 28px;
      border-radius: 20px;
    }
  }
}
</style>